package com.cictec.middleware.gps.engine.position.handler.operateState;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cictec.middleware.commons.utils.Constants;
import com.cictec.middleware.commons.utils.PropertiesUtils;
import com.cictec.middleware.commons.utils.log.MultiLog;
import com.cictec.middleware.gps.engine.BusInstance;
import com.cictec.middleware.gps.engine.exception.BusPositionHandlerException;
import com.cictec.middleware.gps.engine.position.handler.BusPositionDriftHandler;
import com.cictec.middleware.gps.engine.utils.MultiLogUtil;
import com.cictec.middleware.gps.service.BusCharterService;

/**
 * 运营状态处理-【包车计划】影响的运营状态
 * @author ql
 * @date 2017年9月26日
 */
@Service
public class BusCharterHandler implements OperationStateHandler{

	private static Logger logger = LoggerFactory.getLogger(BusPositionDriftHandler.class);
	
	@Autowired
	private BusCharterService busCharterService;
	
	@Override
	public void onHandler(BusInstance busInstance) throws BusPositionHandlerException {
		MultiLog log = MultiLogUtil.getPositionJudgeLog(busInstance);
		
		boolean busCharter = PropertiesUtils.getBoolean("system.parameter.busCharter", false);
		if(busCharter){
			boolean isInbusCharter = busCharterService.isInBusCharterPlan(busInstance.getBusUuid(), busInstance.getTime());
			// 在包车计划中
			if(isInbusCharter){
				busInstance.setAttributeInOperateTime(Constants.VAL_BUS_OPER_STATUS_0);	// 非运营,不再计划运营范围时间内
				String busCharterFlag = PropertiesUtils.getString("system.parameter.busCharter.status", "4");// 包车计划状态标识
				busInstance.setBusCharter(busCharterFlag);
				
				
				logger.debug("\t 包车计划 改变【运营时间状态】【IN_OPER_TIME】 设置为非运营");
				log.debug("\t 包车计划 改变【运营时间状态】【IN_OPER_TIME】 设置为非运营");
			}
		}
		

		
	}

}
